package com.dankegongyu.lib.common.util;

import android.text.TextUtils;

/**
 * Created by Admin on 2017/12/18.
 */

public class NumberParseUtil {

    private NumberParseUtil() {
    }

    public static int parseInt(String number, int def) {
        if (TextUtils.isEmpty(number)) {
            return def;
        }
        int result;
        try {
            result = Integer.parseInt(number);
        } catch (Exception e) {
            e.printStackTrace();
            result = def;
        }
        return result;
    }

    public static float parseFloat(String number, float def) {
        if (TextUtils.isEmpty(number)) {
            return def;
        }
        float result;
        try {
            result = Float.parseFloat(number);
        } catch (Exception e) {
            e.printStackTrace();
            result = def;
        }
        return result;
    }

    public static double parseDouble(String number, double def) {
        if (TextUtils.isEmpty(number)) {
            return def;
        }
        double result;
        try {
            result = Double.parseDouble(number);
        } catch (Exception e) {
            e.printStackTrace();
            result = def;
        }
        return result;
    }

}
